﻿import lightgbm as lgb
import pandas as pd
import numpy as np
import sys
def predict(temperature,flight,cloud,visible):
    dict_keys = ['temperature', 'model_0', 'model_32D',
       'model_33L', 'model_33W', 'model_7M8', 'model_A30B', 'model_A319',
       'model_A320', 'model_A321', 'model_A325', 'model_A330', 'model_A332',
       'model_A333', 'model_AN24', 'model_B707', 'model_B735', 'model_B737',
       'model_B738', 'model_B739', 'model_B757', 'model_B767', 'model_B772',
       'model_B777', 'model_B787', 'model_CRJ', 'model_CRJ9', 'model_E190',
       'model_E195', 'model_ERJ', 'model_JET', 'model_MA6', 'cloud_尘',
       'cloud_无', 'cloud_沙', 'cloud_轻雾', 'cloud_雪', 'cloud_雷暴', 'cloud_雾',
       'cloud_霾', 'visible_低', 'visible_高']

    dict ={}
    for i, val in enumerate(dict_keys):
        dict[val] = i

    data = np.zeros((1,42))
    data[0,0] = temperature
    data[0, dict[flight]] = 1
    data[0, dict[cloud]] = 1
    data[0, dict[visible]] = 1

    gbm = lgb.Booster(model_file='D:\\air\\Civil-Aviation-China-Software\\airplane-admin\\src\\main\\java\\com\\chinasoftware\\civilaviation\\python\\result_model.txt')

    y_pred = gbm.predict(data, num_iteration=gbm.best_iteration)

    #print(float(y_pred[0]))
    return float(y_pred[0])

if __name__ == '__main__':

    print(predict(int(sys.argv[1]),"model_"+sys.argv[2],"cloud_"+sys.argv[3],"visible_"+sys.argv[4]))
    #print(predict(23, 'model_AN24', 'cloud_雷暴', 'visible_高'))